package com.programmercarl.array;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/move-zeroes/description/
 *
 * @author yulongtian
 * @create 2024-12-10 14:37
 */
public class Test08 {
    public static void main(String[] args) {
//        int[] nums = {0, 1, 0, 3, 12};
//        int[] nums = {0};
        int[] nums = {1, 0};
        moveZeroes(nums);
        System.out.println(Arrays.toString(nums));

    }

    public static void moveZeroes(int[] nums) {
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                continue;
            }
            while (true) {
                if (j >= nums.length) {
                    break;
                }
                if (nums[j] != 0 && i < j) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
//                    System.out.println(Arrays.toString(nums) + "  i = " + i + " j = " + j);
                    break;
                } else {
                    j++;
                }
            }

        }
    }

}
